 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Crystal.libs;
using Crystal.Libs;
using Microsoft.Xna.Framework.Graphics;

namespace Crystal.Mapping
{
    [Serializable]
    [MapComponent("FloorCell", "A Floor Cell, for Walking")]
    public class BlankFloorCell : CellBase
    {
        //Fields 
		private FloorTypeEnum _FloorType; 
		public FloorTypeEnum FloorType
		{
			get { return _FloorType; }
			set { _FloorType = value; }
		} 
				
        //cTor
        public BlankFloorCell(Game game, MazePosition position)
            : base(game, position)
        {
            this.CellPrimitive.Rescale(Globals.CellFloorSize);
            this.FloorType = (FloorTypeEnum)Globals.GlobalRandomizer.Next(0, Enum.GetValues(typeof(FloorTypeEnum)).Length);
        }

        //Methods
        public override void UpdateCell(GameTime time)
        {
        }
        public override void RenderCell()
        {
            Matrix[] transforms = new Matrix[Resources.CellFloorModels[(int)FloorType].Bones.Count];
            Resources.CellFloorModels[(int)FloorType].CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in Resources.CellFloorModels[(int)FloorType].Meshes)
            {
                foreach (Effect fx in mesh.Effects)
                {
                    fx.CurrentTechnique = fx.Techniques["ColorShade"];

                    fx.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * CellPrimitive.World);
                    fx.Parameters["View"].SetValue(Globals.GameCamera.View);
                    fx.Parameters["Projection"].SetValue(Globals.GameCamera.Projection);
                    fx.Parameters["Texture"].SetValue(Crystal.Libs.Resources.WallMap);

                    fx.Parameters["AmbientColor"].SetValue(Globals.AmbientLightColor);
                    fx.Parameters["AmbientLevel"].SetValue(Globals.AmbientLightLevel);
                }
                mesh.Draw();
            }
        }
    }
}